home *** CD-ROM | disk | FTP | other *** search
/ Merciful 2 / Merciful - Disc 2.iso / software / p / personalpaintv6.3a.dms / personalpaintv6.3a.adf / Rexx / GifToPng.pprx next >
Text File  |  1995-05-31  |  5KB  |  169 lines

  1. /* PPaint Amiga Rexx script - Copyright © 1995 Cloanto Italia srl */
  2.  
  3. /*
  4.   $VER: GifToPng.pprx 1.0
  5.  
  6.   This script asks the user to specify a directory, scans the directory
  7.   and its subdirectories and converts all GIF files it finds into PNG.
  8.  
  9.   Non-GIF files are not affected. Icon images are preserved. Icon format
  10.   information is updated (Tool Types: FILETYPE=PNG). File name suffixes are
  11.   changed (i.e. the files are renamed) as follows:
  12.  
  13.     .gif   -> .png
  14.     .GIF   -> .PNG
  15.     .Gif   -> .Png, ecc.
  16.  
  17.     others -> unchanged
  18.  
  19.   Personal Paint identifies the file type by its contents (not by the file
  20.   name suffix). If the script runs during Workbench use, the Workbench Update
  21.   menu item must be selected to visually update the contents of any windows
  22.   containing files being renamed by this script.
  23.  
  24.   This script requires Personal Paint version 6.3 (PPaint Rexx version 2)
  25.   or higher, personal_png_io.library (enclosed with PPaint), and
  26.   personal_gif_io.library (available via free electronic distribution).
  27.  
  28.  
  29.   Possible changes that could be applied to this file:
  30.  
  31.     Convert all images to PNG (not just GIFs). To do this, change the line
  32.     selecting GIFs to IF UPPER(RESULT) ~= 'PNG' THEN DO. However, be careful
  33.     if you have IFF animations, as they would be processed as ILBM images
  34.     (IFF animations begin with an ILBM image).
  35.  
  36.     Activate PNG Adam 7 progressive display in files being written. This
  37.     degrades compression but the resulting images appear more nicely when
  38.     displayed by progressive viewers. Set PROGDSP=1.
  39.  
  40.     Convert any file to uncompressed IFF-ILBM. This may be good for files to
  41.     be stored on an Amiga CD-ROM, where loading speed could be more important
  42.     than compression. Remove the instructions selecting only GIFs and replace
  43.     the PNG FORMAT option with FORMAT ILBM OPTIONS "COMPR=0" "SCRFMT=0".
  44.  
  45.  
  46.   PNG was designed as a replacement and extension to GIF and LZW-based TIFF,
  47.   after Unisys Corporation began demanding royalties on GIF/LZW code. As
  48.   the PNG specification was released in May 1995, it gained general
  49.   recognition as the best lossless standard for storing digital images.
  50.  
  51.   Cloanto, the first software house to publish a paint program supporting the
  52.   PNG file format, is also making available a PNG developer's kit for the
  53.   Amiga. This includes instructions for using personal_png_io.library, and is
  54.   a commercial product. A PNG DataType is available at no cost for free
  55.   electronic distribution.
  56.  
  57.   An article on the GIF/LZW issue can be requested by sending E-mail to
  58.  
  59.     <gltext1@cloanto.it>
  60.  
  61.   For more information, or suggestions, please address E-mail to
  62.  
  63.     <info@cloanto.it>
  64.  
  65. */
  66.  
  67.  
  68. MYPORT = 'PPAINT'
  69.  
  70. IF ~SHOW('P', MYPORT) THEN DO
  71.     IF EXISTS('PPaint:PPaint') THEN DO
  72.         ADDRESS COMMAND 'Run >NIL: PPaint:PPaint'
  73.         DO 30 WHILE ~SHOW('P',MYPORT)
  74.              ADDRESS COMMAND 'Wait >NIL: 1 SEC'
  75.         END
  76.     END
  77.     ELSE DO
  78.         SAY "Personal Paint could not be loaded."
  79.         EXIT 10
  80.     END
  81. END
  82.  
  83. IF ~SHOW('P', MYPORT) THEN DO
  84.     SAY 'Personal Paint Rexx port could not be opened.'
  85.     EXIT 10
  86. END
  87.  
  88. ADDRESS VALUE MYPORT
  89. OPTIONS RESULTS
  90. OPTIONS FAILAT 10000
  91.  
  92. Version 'REXX'
  93. IF RESULT < 2 THEN DO
  94.     errmess = 'This script requires a newer_version of Personal Paint.'
  95.     SAY errmess
  96.     RequestNotify 'PROMPT="'errmess'"'
  97.     EXIT 10
  98. END
  99.  
  100. LockGUI
  101. FreeBrush
  102. IF RC = 0 THEN RequestPath '"GifToPng target directory"'
  103. IF RC = 0 THEN DO
  104.     tmpfname = 'T:pprx_temp.'PRAGMA('ID')
  105.     ADDRESS COMMAND 'List >'tmpfname' 'RESULT' NOHEAD PAT=~(#?.info) LFORMAT="*"%s%s*"" ALL FILES'
  106.     IF OPEN('listfile', tmpfname, R) THEN DO
  107.         Get SETTING ICONS
  108.         iconmode = RESULT
  109.         errcode = 0
  110.         Set '"ICONS=3"'
  111.         DO FOREVER
  112.             curfname = READLN('listfile')
  113.             IF EOF('listfile') THEN BREAK
  114.             GetFileFormat curfname
  115.             IF RC = 0 THEN DO
  116.                 IF UPPER(RESULT) = 'GIF' THEN DO
  117.                     SAY 'Processing 'curfname
  118.                     LoadBrush curfname FORCE
  119.                     IF RC = 0 THEN DO
  120.                         IF UPPER(RIGHT(curfname, 5)) = '.GIF"' THEN DO
  121.                             len = LENGTH(curfname)
  122.                             newfname = OVERLAY(D2C(C2D(SUBSTR(curfname, len-3, 1)) + 9), curfname, len-3)
  123.                             newfname = OVERLAY(D2C(C2D(SUBSTR(curfname, len-2, 1)) + 5), newfname, len-2)
  124.                             newfname = OVERLAY(D2C(C2D(SUBSTR(curfname, len-1, 1)) + 1), newfname, len-1)
  125.                             IF EXISTS(SUBSTR(newfname,2,len-2)) = 0 THEN DO
  126.                                 ADDRESS COMMAND 'Rename >NIL: 'curfname' 'newfname
  127.                                 curiconfname = INSERT('.info', curfname, len-1)
  128.                                 newiconfname = INSERT('.info', newfname, len-1)
  129.                                 curfname = newfname
  130.                                 IF EXISTS(SUBSTR(curiconfname,2,len+3)) THEN DO
  131.                                     IF EXISTS(SUBSTR(newiconfname,2,len+3)) THEN
  132.                                         ADDRESS COMMAND 'Delete >NIL: 'curiconfname
  133.                                     ELSE
  134.                                         ADDRESS COMMAND 'Rename >NIL: 'curiconfname' 'newiconfname
  135.                                 END
  136.                             END
  137.                         END
  138.                         SaveBrush 'FORCE FILE 'curfname' FORMAT PNG OPTIONS "PROGDSP=0" "COMPR=6" "AUTO=1"'
  139.                         IF RC > 0 THEN DO
  140.                             errcode = RC
  141.                             IF RC = 5 THEN
  142.                                 errmess = 'User abort during save.'
  143.                             ELSE
  144.                                 errmess = 'Error 'RC' during save.'
  145.                         END
  146.                         FreeBrush FORCE
  147.                     END
  148.                     ELSE DO
  149.                         errcode = RC
  150.                         IF RC = 5 THEN
  151.                             errmess = 'User abort during load.'
  152.                         ELSE
  153.                             errmess = 'Error 'RC' during load.'
  154.                     END
  155.                 END
  156.             END
  157.             IF errcode > 0 THEN BREAK
  158.         END
  159.         IF errcode > 0 THEN DO
  160.             SAY errmess
  161.             RequestNotify 'PROMPT="'errmess'"'
  162.         END
  163.         Set '"ICONS='iconmode'"'
  164.         CALL CLOSE('listfile')
  165.     END
  166.     ADDRESS COMMAND 'Delete >NIL: 'tmpfname
  167. END
  168. UnlockGUI
  169.